<?php if($this->search) echo $this->headScript();?>
<div class="list-resumes clearfix">
    <div class="head">
        <div class="checkbox">
            &nbsp;
        </div>
        <div class="name">
            <h4>Name</h4>
        </div>
        <div class="experience">
            <h4>Experience</h4>
        </div>
        <div class="salary">
            <h4>Desired salary</h4>
        </div>
        <div class="comments">
            <h4>Commentd</h4>
        </div>
        <div class="sent">
            <h4>History</h4>
        </div>
    </div>
    <?php 
    $experienceMapper = new Default_Model_ExperienceMapper();
    $expectationMapper = new Default_Model_ExpectationMapper();
    $resumeMapper = new Default_Model_ResumeMapper();
    $userMapper = new Default_Model_User();

    foreach ( $this->paginator as $row ) :
        $consultantCreated = $userMapper->getConsultantName($row['created_consultant_id']);
        $consultantUpdated = $userMapper->getConsultantName($row['updated_consultant_id']);
        $date = new DateTime($row['updated_date']);
        $updatedDate = $date->format('d M Y');
        $experienceList = $experienceMapper->fetchAll('resume_id = ' . $row['resume_id'], 'end_date DESC');
        $comment = $resumeMapper->getComments($row['resume_id'], 1);
        $date = new DateTime($comment['created_date']);
        $createdComment = $date->format('M-d');
        $historys = $resumeMapper->getHistory($row['resume_id'], 3);
    ?>
    <div class="info-content">
        <div class="checkbox">
            <input type="checkbox" name="resume_chk[]" value="<?php echo $row['resume_id']?>">
        </div>
        <div class="name">
            <h4>
                <a href="#detail_resume" class="detail_resume" id="<?php echo $row['resume_id']?>"><?php echo $row['full_name'];?></a>
            </h4>
            <p><?php echo $row['resume_code'];?></p>
            <?php if($row['mobile_1']) : ?>
                <p>Phone: <?php echo $row['mobile_1'];?></p>
            <?php endif;?>
            <?php if($row['mobile_2']) : ?>
                <p>Phone: <?php echo $row['mobile_2'];?></p>
            <?php endif;?>
            <?php if($row['tel']) : ?>
                <p>Tel: <?php echo $row['tel'];?></p>
            <?php endif;?>
        </div>
        <div class="experience">
            <ul>
            <?php 
            $i = 1;
            foreach ( $experienceList as $experience ) :
                if($i > 3) break;
            ?>
                <li>
                    <div style="width:30%;float:left"><?php echo $experience->getStartDate();?><?php echo ($experience->getEndDate())? ' - ' . $experience->getEndDate():'&nbsp;';?></div>
                    <div class="companies" style="width:65%;float:left">
                        <?php if($experience->getExperienceOther()) :?>
                            <p>Experience Other</p>
                        <?php else:?>
                        <p style="color:#227DBA;font-weight:bold;text-transform: uppercase;"><?php echo $experience->getCompanyName();?></p>
                        <p><?php echo $experience->getJobTitle();?></p>
                        <?php endif?>
                    </div>
                </li>
            <?php
            $i++;
            endforeach;?>
            </ul>
        </div>
        <?php
        $expectation = $expectationMapper->getExpectation($row['resume_id']);
        $provinceArr = array();
        if($expectation['res_expectation_id']) {
            $resumeProvince = $expectationMapper->getExpectationProvince($expectation['res_expectation_id']);
            foreach($resumeProvince as $province){
                $provinceArr[] = $province['name'];
            }
        }

        $currentSalary = number_format($expectation['current_salary']);
        @$salaryFrom = number_format($expectation['estimated_salary_from']);
        @$salaryTo = number_format($expectation['estimated_salary_to']);
        ?>
        <div class="salary">
            <p>[S]: <?php if($currentSalary) echo '$'.$currentSalary; ?></p>
            <p>[E]: <?php if($salaryFrom) echo '$'.$salaryFrom; ?><?php if($salaryTo) echo ' - '.'$'.$salaryTo; ?></p>
            <p>[L]: <?php echo implode(', ', $provinceArr);?></p>
            <p class="update-date">
                Update: <?php echo $updatedDate; ?><br />
                <?php if($consultantUpdated['username']) ?>Updated By: <?php echo $consultantUpdated['username']; ?><br />
                Created By: <?php echo $consultantCreated['username']; ?><br />
            </p>
        </div>
        <div class="comments">
			<a href="#comment" class="addcomment" id="<?php echo $row['resume_id']?>">Add Comment</a>
		<?php if(@$row['file_resume']) : ?>
			<a href="/resume/download-resume/id/<?php echo $row['resume_id']?>" class="export-word">Download Resume</a>
		<?php else : ?>
            <a href="/resume/export-to-word/id/<?php echo $row['resume_id']?>" class="export-word">Export to word</a>
		<?php endif;?>
            <div class="info-comment" id="viewcomment<?php echo $row['resume_id']?>">
                <?php if($comment):?>
                <p class="update-date">Comment <?php echo $createdComment;?></p> <span>by</span> <span class="user-name"><?php echo $comment['username'];?></span>
                <p><?php echo substr($comment['content'], 0, 90);?></p>
                <a href="#allcomment"  class="allcomment" id="<?php echo $row['resume_id'] ?>">View all</a>
                <?php endif;?>
            </div>
        </div>
        <div class="sent">
            <a href="#history" class="addhistory" id="<?php echo $row['resume_id']?>">Add History</a>
            <div class="info-comment" id="viewhistory<?php echo $row['resume_id']?>">
            <?php if(count($historys) > 1):?>
            <?php foreach($historys as $history):?>
                <p> - <?php echo substr($history['content'], 0, 90);?></p>
            <?php endforeach;?>
            <a href="#allhistory"  class="allhistory" id="<?php echo $row['resume_id'] ?>">View all</a>
            <?php endif;?>
            </div>
        </div>
        
    </div>
    <?php endforeach;?>
</div> 
<div style="clear:both">&nbsp;</div>
<!-- pagging -->
<div class="footer clearfix">
	<b>Show</b>
    <select name="rowperpage" id="rowperpage">
    	<option value="20" <?php echo ($this->paginator->getItemCountPerPage() == '20')? 'selected': ''?>>20</option>
		<option value="30" <?php echo ($this->paginator->getItemCountPerPage() == '30')? 'selected': ''?>>30</option>
		<option value="50" <?php echo ($this->paginator->getItemCountPerPage() == '50')? 'selected': ''?>>50</option>
		<option value="100" <?php echo ($this->paginator->getItemCountPerPage() == '100')? 'selected': ''?>>100</option>
	</select>
    <?php if(count($this->paginator)) :?>
        <?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml', array('rowperpage' => $this->paginator->getItemCountPerPage(), 'choice' => $this->choice, 'search' => $this->search)); ?>
    <?php endif;?>
</div>
